<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <script>
        //有迭代器Symbol iterator 接口，就可以通过for...of 枚举出来
        // const users = ['苹果','榴莲']
        // const iter =users[Symbol.iterator]()
        // //调用next会返回当前迭代的值，默认为falase,直到最后一个结束为undefined，默认值为true
        // console.log(iter.next())
        // console.log(iter.next())

        // console.log(iter.next())
        
        // for(var item of users){
        //     console.log(item)
        // }

        //重写自定义迭代器
        const users =['apple','banana','orange','pear',]
        users[Symbol.iterator] =function(){
            let i = 0;
           return {
            next:( ) => {
                let value = this[2*i++]
                return{
                    value,
                    done:value? false :true
                }
            }
           }
        }
        // const iterator = users[Symbol.iterator]()
        // for(var item of iterator){
        //     console.log(item)
        // }
    </script>
</body>
</html>